/* eslint-disable */
Number.prototype.toFixed = function(n) {
  if (n == null) {
    return this.toString()
  }

  n = Number(n)

  if (Number.isNaN(n)) {
    return this.toString()
  }

  if (n < 0 || n > 100) {
    throw new Error('toFixed() digits argument must be between 0 and 100')
  }

  let num = this
  const base = Math.pow(10, n)
  num = Math.round(num * base) / base
  let numText = num.toString()
  let dotIndex = 0

  if ((dotIndex = numText.indexOf('.')) < 0) {
    if (n == 0) {
      return numText
    }

    numText = numText + '.'
    for (let i = 0; i < n; i++) {
      numText += '0'
    }

    return numText
  }

  const part0 = numText.substring(0, dotIndex)
  let part1 = numText.substring(dotIndex + 1)
  let part1Length = part1.length
  if (part1Length < n) {
    for (let i = 0; i < n - part1Length; i++) {
      part1 += '0'
    }
  } else {
    part1 = part1.substring(0, n)
  }

  return part0 + '.' + part1
}
